package com.markyao.utils;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class EncoderUtils {
    private final static Base64.Encoder encoder=Base64.getEncoder();
    private final static Base64.Decoder decoder=Base64.getDecoder();
    public static String encode(String str){
        try {
            byte[] bytes = str.getBytes("UTF-8");
            String s = encoder.encodeToString(bytes);
            System.out.println(s);
            return s;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return str;
    }

    public static String decode(String str){
        try {
            String s = new String(decoder.decode(str), "UTF-8");
            System.out.println(s);
            return s;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return str;
    }


}
